#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include "md5.h"
#include "hmac_md5.h"

void printres(const uint8_t *res) {
    for (int i = 0; i < 16; ++i) {
        printf("%02x", res[i]);
    }
}

int main() {
    md5_init();

    puts("------------- md5 test ----------------");
    const char message[] = "The quick brown fox jumps over the lazy dog";
    printf("message: %s\n", message);
    int length = strlen(message) * sizeof(message[0]);
    printf("length: %d\n", length);

    uint8_t digest[16];
    md5(digest, (uint8_t*)message, length);
    printf("digest: ");
    printres(digest);
    printf("\n\n");

    puts("------------ hmac-md5 test -------------");
    const char key[] = "mysecretkey";
    int length_key = strlen(key) * sizeof(key[0]);
    printf("message: %s\n", message);
    printf("message length: %d\n", length);
    printf("key: %s\n", key);
    printf("key length: %d\n", length_key);
    uint8_t hmac[16];
    hmac_md5(hmac, (uint8_t*)message, length, (uint8_t*)key, length_key);
    printf("hmac: ");
    printres(hmac);
    printf("\n\n");
    return 0;
}
